// 1. 导入localize模块函数
import {extend, localize} from 'vee-validate'
// 导入全部的规则
import * as rules from 'vee-validate/dist/rules'

// 2.导入要使用的语言
import zh_CN from 'vee-validate/dist/locale/zh_CN.json'




// 遍历、注册全部的规则
Object.keys(rules).forEach(rule => {
    extend(rule, rules[rule])
})

extend('password', {
    validate(value, {min, max}) {
        return value.length >= min && value.length <= max
    },
    params: ['min', 'max']
});
extend('realName',{
    validate: value => {
        const reg = /(?:[\u4E00-\u9FFF]{1,8}·\u4E00-\u9FFF]{1,8})|(?:[\u4E00-\u9FFF]{2,5})/;
        return reg.test(value)
    },
    message: '请输入真实姓名'


});
extend('phone', {
        validate: value => {
            const reg = /^1[35789]\d{9}$/ // 正则校验手机号码
            return reg.test(value) // 正则匹配目标内容，返回boolean
        },

    }
);


// 3.对导入好的语言做注册
localize({
    zh_CN: {
        names: {
            phone: '手机号码',
            password: '密码'
        },
        messages: {
            ...zh_CN.messages,//加载错误信息
            required: '请输入{_field_}',
            phone: '请输入正确的电话格式',
            password: '密码应大于{min}小于{max}'
        },
        // fields: {
        //     password: {
        //         required: 'Password cannot be empty!',
        //         max: 'Are you really going to remember that?',
        //         min: 'Too few, you want to get doxed?'
        //     }
        // },

    },

});

localize("zh_CN")



